/***************************************************************
 * Name:      chipplayerApp.cpp
 * Purpose:   Code for Application Class
 * Author:    m7 ()
 * Created:   2008-12-03
 * Copyright: m7 ()
 * License:
 **************************************************************/

/*
__GNUWIN32__
__WXMSW__

#define wxUSE_UNICODE
*/

#ifdef WX_PRECOMP
#include "wx_pch.h"
#endif

#ifdef __BORLANDC__

#pragma hdrstop
#endif //__BORLANDC__

#include "chipplayerApp.h"
#include "common.h"
#include "chipFrame.h"

IMPLEMENT_APP(chipplayerApp);
DEFINE_EVENT_TYPE(listBoxEvent)	/// for change title, slider range
DEFINE_EVENT_TYPE(myEvent)

bool chipplayerApp::OnInit() {
///	wxImage::AddHandler(new wxPNGHandler);

    chippy = new chipFrame(0);



	wxTextFile tryopen(filenameSession); long int mus=-1, seek = -1;
	if ( tryopen.Exists() ) {
		tryopen.Open();
		wxString str;
		int i = 0;	/// current line in sessionfile
		wxArrayString* path;
		if (tryopen.GetLineCount() < 6 ) goto show;  /// trying if not empty

		if (!aychipIdentifer.IsSameAs(tryopen.GetLine(i++))) goto show;
		if (currSongz.IsSameAs(tryopen.GetLine(i))) {
			i++;
			if( !tryopen.GetLine(i++).ToLong(&mus)) goto show;
			if (!currSongPozition.IsSameAs(tryopen.GetLine(i++))) goto show;
			if( !tryopen.GetLine(i++).ToLong(&seek)) goto show;
		}
		/// may be i = 2, if no played in close :)
		if (!lastFilez.IsSameAs(tryopen.GetLine(i++)))	goto show;

		path = new wxArrayString;

		for(int j=i; j < tryopen.GetLineCount(); j++) {
			path->Add(tryopen.GetLine(i++));
		}
		chippy->addFilesToCurrentPlayListFast(*path);
		delete path;

		if (seek >= 0 && mus >= 0) {
			chippy->player->play(chippy->player->playList, mus, true);	/// play muzz
			ay_seeksong(chippy->player->currentSong, seek);		/// and seek
		}
	}
show:
	chippy->setPlayIcon();

	chippy->timer.Start(20, false);	//// for 50hz to indicatorz

    chippy->Show();

    return true;
}
